import { getUsersService } from "@/services/user";
import { Button } from "antd";
import { useDispatch, useSelector } from "react-redux";
import { increment } from "@/store/counterSlice";
import { changeCounterAsync } from "./../../store/counterSlice";

export default () => {
  const getUsers = async () => {
    try {
      const data = await getUsersService();
    } catch (error) {}
  };

  const counter = useSelector((state) => state.counter.count);
  const dispatch = useDispatch();
  const setCounter = () => {
    dispatch(increment(3));
  };
  const setCounterAsync = () => {
    dispatch(changeCounterAsync({ value: "嘿嘿" }));
  };
  return (
    <div>
      用户管理
      <Button type={"primary"} onClick={getUsers}>
        获取用户信息
      </Button>{" "}
      <br />
      <p>{counter}</p>
      <Button type={"primary"} onClick={setCounter}>
        +1 测试redux 同步处理全局状态
      </Button>
      <Button type={"primary"} onClick={setCounterAsync}>
        测试redux 异步处理全局状态
      </Button>
    </div>
  );
};
